package com.google.code.onlineshopping4j.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class Order extends BaseModel implements Serializable {

	private static final long serialVersionUID = 8855002230492569567L;
	private final Date dateTimeOfSubmission;
	private Map<String, Integer> orderItems;
	private final UUID key;
	private Customer customer;
	private OrderStatus status;
	private List<OrderStatus> statusHistory;

	public Order(final Date dateTimeOfSubmission) {
		this.key = UUID.randomUUID();
		this.dateTimeOfSubmission = dateTimeOfSubmission;
		statusHistory = new ArrayList<OrderStatus>();
	}

	public void addStatus(OrderStatus newStatus) {
		statusHistory.add(newStatus);
		status = newStatus;
	}

	public OrderStatus getStatus() {
		return status;
	}

	public Date getDateTimeOfSubmission() {
		return dateTimeOfSubmission;
	}

	public UUID getKey() {
		return key;
	}

	public void setOrderItems(Map<String, Integer> orderItems) {
		if (orderItems == null) {
			this.orderItems = Collections.emptyMap();
		} else {
			this.orderItems = Collections.unmodifiableMap(orderItems);
		}
	}

	public Map<String, Integer> getOrderItems() {
		return orderItems;
	}

	public boolean canBeDeleted() {
		return true;
	}
}
